local sk__jiaozhao = fk.CreateSkill {

  name = "sk__jiaozhao",

  tags = {},

}



sk__jiaozhao:addEffect("active", {
  name = "sk__jiaozhao",
  anim_type = "control",
  prompt = "#sk__jiaozhao",
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("bt")
    local names = {}
    for _, name in ipairs(all_names) do
      local card = Fk:cloneCard(name)
      if card.skill:canUse(player, card, { bypass_times = true, bypass_distances = true }) or
          table.contains({ "peach", "ex_nihilo", "foresight", "wd_rice" }, card.trueName) or --默认目标救救
          card.multiple_targets then
        table.insert(names, name)
      end
    end
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(sk__jiaozhao.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_filter = function(self, player, to_select, selected, selected_cards)
    if #selected_cards == 1 and self.interaction.data then
      local card = Fk:cloneCard(self.interaction.data)
      card:addSubcards(selected_cards)
      if #selected >= card.skill:getMaxTargetNum(player, card) then return false end
      if card.skill:getMinTargetNum(player) == 2 then
        return not (#selected == 0 and to_select == player)
      else
        return to_select ~= player
      end
    end
  end,
  feasible = function(self, player, selected, selected_cards, card)
    if #selected_cards == 1 and self.interaction.data then
      local card = Fk:cloneCard(self.interaction.data)
      card:addSubcards(selected_cards)
      if #selected >= card.skill:getMinTargetNum(player) and #selected <= card.skill:getMaxTargetNum(player, card) then
        if card.skill:getMinTargetNum(player) == 0 then
          return #selected > 0 or card.multiple_targets
        else
          return true
        end
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(effect.cards)
    card.skillName = sk__jiaozhao.name
    if #effect.tos == 0 and card.multiple_targets and card.skill:getMinTargetNum(player) == 0 then
      effect.tos = table.map(room:getOtherPlayers(player), function(p)
        if card.skill:modTargetFilter(effect.from, p, {}, card) then
          return p
        end
      end)
    end
    room:useCard({
      from = effect.from,
      tos = effect.tos,
      card = card,
      extraUse = true,
    })
  end,
})

return sk__jiaozhao
